/**
 * @author Luc Yriarte
 * 
 * Licence : BSD http://www.opensource.org/licenses/bsd-license.php
 *  
 */
package basicSim;

public class Vector3D extends Vector {

	static public Vector3D MatrixAsVector3D(Matrix aMatrix) {
		return new Vector3D(aMatrix.cell);
	}
	
	/**
	 * [0,0,0,1]
	 */
	public Vector3D() {
		super(4);
		cell[0][0] = 0;
		cell[1][0] = 0;
		cell[2][0] = 0;
		cell[3][0] = 1;
	}

	/**
	 * [x,y,z,1]
	 */
	public Vector3D(double x, double y, double z) {
		super(4);
		cell[0][0] = x;
		cell[1][0] = y;
		cell[2][0] = z;
		cell[3][0] = 1;
	}
	
	public Vector3D(double[][] cell) {
		nLines = 4;
		nCols = 1;
		this.cell = cell;
	}

	public Vector3D(Matrix aMatrix) {
		super(4);
		cell[0][0] = aMatrix.cell[0][0];
		cell[1][0] = aMatrix.cell[1][0];
		cell[2][0] = aMatrix.cell[2][0];
		cell[3][0] = 1;
	}

	public Vector3D(Matrix aMatrix, int column) {
		super(4);
		cell[0][0] = aMatrix.cell[0][column];
		cell[1][0] = aMatrix.cell[1][column];
		cell[2][0] = aMatrix.cell[2][column];
		cell[3][0] = 1;
	}

	public Matrix3D positionMatrix() {
		return Matrix3D.translation(this.cell[0][0],this.cell[1][0],this.cell[2][0]);
	}

	/**
	 * @param aMatrix
	 * @return this = aMatrix * this
	 */
	public Vector3D transformThis(Matrix aMatrix) {
		double x,y,z;
		x = (aMatrix.cell[0][0] * this.cell[0][0])
		  + (aMatrix.cell[0][1] * this.cell[1][0])
		  + (aMatrix.cell[0][2] * this.cell[2][0])
		  +  aMatrix.cell[0][3];
		y = (aMatrix.cell[1][0] * this.cell[0][0])
		  + (aMatrix.cell[1][1] * this.cell[1][0])
		  + (aMatrix.cell[1][2] * this.cell[2][0])	
		  +  aMatrix.cell[1][3];
		z = (aMatrix.cell[2][0] * this.cell[0][0])
		  + (aMatrix.cell[2][1] * this.cell[1][0])
		  + (aMatrix.cell[2][2] * this.cell[2][0])
		  +  aMatrix.cell[2][3];
		this.cell[0][0] = x;
		this.cell[1][0] = y;
		this.cell[2][0] = z;
		return this;
	}
	
	
}
